package org.exam.system.controller;

import org.exam.exception.BusinessException;
import org.exam.system.domain.Logininfo;
import org.exam.system.dto.LoginDto;
import org.exam.system.service.ILogininfoService;
import org.exam.system.service.impl.LogininfoServiceImpl;
import org.exam.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILogininfoService logininfoService;
    @PostMapping("/account")
//    定义一个方法来获取最后的token值来传给前端
    public JsonResult accountLogin(@RequestBody LoginDto loginDto) {
        try {
//            最后的token值
            String jwtToken = logininfoService.accountLogin(loginDto);
            return JsonResult.success(jwtToken);
        } catch (BusinessException e) {
            return JsonResult.error(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error("网络繁忙");
        }

    }

}
